option(HAIRENGINE_BUILD_TEST "Build the google test instead of the executable file" ON)

set(HAIRENGINE_SOURCE_FILES
        src/core/hairgeo/hairgeo.cpp
        src/core/collider/collider.cpp
        src/core/collider/sdfcollider.cpp
        src/core/engine/hairengine.cpp
        src/core/engine/strandbasedhe.cpp
        src/core/engine/andrewsellehe.cpp
        src/core/solver/hair.cpp)

set(HAIRENGINE_INCLUDE_DIR_SOURCE ./src)
set(HAIRENGINE_INCLUDE_DIR_SOURCE ${HAIRENGINE_INCLUDE_DIR_SOURCE} ${PROJECT_SOURCE_DIR}/ext)
set(HAIRENGINE_INCLUDE_DIR)
set(HAIRENGINE_LIBRARY)

find_package(EIGEN3 REQUIRED)
if (EIGEN3_FOUND)
    set(HAIRENGINE_INCLUDE_DIR ${HAIRENGINE_INCLUDE_DIR} ${EIGEN3_INCLUDE_DIR})
endif (EIGEN3_FOUND)

find_package(TBB REQUIRED)
if (TBB_FOUND)
    set(HAIRENGINE_INCLUDE_DIR ${HAIRENGINE_INCLUDE_DIR} ${TBB_INCLUDE_DIR})
    set(HAIRENGINE_LIBRARY ${HAIRENGINE_LIBRARY} ${TBB_LIBRARY})
endif(TBB_FOUND)

if (HAIRENGINE_BUILD_TEST)
    set(
            HAIRENGINE_TEST_FILE
            src/test/main.cpp
            src/test/teststrandmassdistributor.cpp
            src/test/testmathutil.cpp
            src/test/testhairdata.cpp
            src/test/testhair.cpp
            src/test/testconfig.cpp
    )
    find_package(GTEST REQUIRED)
    if (GTEST_FOUND)
        set(HAIRENGINE_INCLUDE_DIR ${HAIRENGINE_INCLUDE_DIR} ${GTEST_INCLUDE_DIR})
        set(HAIRENGINE_INCLUDE_DIR_SOURCE ${HAIRENGINE_INCLUDE_DIR_SOURCE} src/test)
        set(HAIRENGINE_LIBRARY ${HAIRENGINE_LIBRARY} ${GTEST_LIBRARY})
    endif(GTEST_FOUND)
    MESSAGE(STATUS "Currently build the test file")
    MESSAGE(STATUS "Currently include directory: ${HAIRENGINE_INCLUDE_DIR}")
    MESSAGE(STATUS "Currently link library: ${HAIRENGINE_LIBRARY}")

    add_executable(HairEngineTest ${HAIRENGINE_TEST_FILE} ${HAIRENGINE_SOURCE_FILES})
    target_include_directories(HairEngineTest SYSTEM PUBLIC ${HAIRENGINE_INCLUDE_DIR})
    target_include_directories(HairEngineTest PUBLIC ${HAIRENGINE_INCLUDE_DIR_SOURCE})
    target_link_libraries(HairEngineTest ${HAIRENGINE_LIBRARY})
    target_compile_definitions(HairEngineTest PUBLIC HAIRENGINE_TEST=1)
endif(HAIRENGINE_BUILD_TEST)

set(HAIRENGINE_MAIN_FILE src/main/main.cpp)

add_executable(HairEngine ${HAIRENGINE_MAIN_FILE} ${HAIRENGINE_SOURCE_FILES})
target_include_directories(HairEngine SYSTEM PUBLIC ${HAIRENGINE_INCLUDE_DIR})
target_include_directories(HairEngine PUBLIC ${HAIRENGINE_INCLUDE_DIR_SOURCE})
target_link_libraries(HairEngine ${HAIRENGINE_LIBRARY})

if (HAIRENGINE_SOURCE_FILES)
    add_library(libhairengine SHARED ${HAIRENGINE_SOURCE_FILES})
    target_include_directories(libhairengine SYSTEM PUBLIC ${HAIRENGINE_INCLUDE_DIR})
    target_include_directories(libhairengine PUBLIC ${HAIRENGINE_INCLUDE_DIR_SOURCE})
    target_link_libraries(libhairengine ${HAIRENGINE_LIBRARY})
endif (HAIRENGINE_SOURCE_FILES)